package net.m510.autosurfer.smbc;

import java.net.URI;
import java.util.logging.Logger;

import net.m510.autosurfer.common.DocumentGetProcess;
import net.m510.autosurfer.common.exception.InvalidDocumentException;

import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class SmbcLogout extends DocumentGetProcess {
	private static final Logger log = Logger.getLogger(SmbcLogout.class.getName());

	public SmbcLogout() {
		this(null,null);
	}
	
	public SmbcLogout(CloseableHttpClient client,HttpClientContext context) {
		super(client, context);
		super.log = log;
	}

	@Override
	protected URI getUri(Document doc) {
		// ログアウト用URLの取得1
		final String LOGOUT_STR="ログアウト";
		Elements es = doc.getElementsMatchingOwnText(LOGOUT_STR);
		if ( es.isEmpty()) throw new InvalidDocumentException(LOGOUT_STR+"の文字列が、見つかりません",doc);
		log.fine("logout html="+es.first());
		String href = es.first().attr("href");
		if ( href.length() == 0 ) throw new InvalidDocumentException("ログアウト用のhrefが見つかりません",doc);
		return URI.create(href);
	}

}
